package com.lishe.lishe.lishe.module.mall.adapter;


import android.app.Activity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.lishe.base.common.adapter.CommonAdapter;
import com.lishe.base.common.adapter.base.ItemViewDelegate;
import com.lishe.base.common.adapter.base.ViewHolder;
import com.lishe.base.view.FullGridLayoutManager;
import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerGriadViewItemDecoration;
import com.lishe.lishe.lishe.module.mall.bean.DataItemBean;
import com.lishe.lishe.lishe.module.mall.bean.GoodsItemsBean;
import com.lishe.lishe.lishe.module.mall.presenter.IndexPresenter;
import com.lishe.lishe.lishe.utils.Utils;

/**
 * 标    题：超值专区
 * 功能描述：
 * 作    者：zouxx
 * 创建时间：2018/8/14
 */

public class TitleItemViewDelegate implements ItemViewDelegate<DataItemBean> {

    private final RecyclerGriadViewItemDecoration decoration;
    private Activity activity;

    public TitleItemViewDelegate(Activity activity) {
        this.activity = activity;
        decoration = new RecyclerGriadViewItemDecoration(Utils.dip2px(activity, 8), 0, 0);
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_index_recyclerview;
    }

    @Override
    public boolean isForViewType(DataItemBean item, int position) {
        return item.style == 5;
    }

    @Override
    public void convert(ViewHolder holder, DataItemBean dataBean, int position) {
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        holder.itemView.setLayoutParams(params);
        RecyclerView recyclerView = holder.getView(R.id.item_recyclerView);
        holder.setVisible(R.id.rl_title, true);
        ImageLoaderUtils.displayImage(activity, dataBean.iconUrl, holder.getView(R.id.icon),R.drawable.defalut_img);
        holder.setText(R.id.title, dataBean.title);
        GridLayoutManager layoutManager = new GridLayoutManager(activity, 2);
        layoutManager.setAutoMeasureEnabled(true);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.removeItemDecoration(decoration);
        recyclerView.addItemDecoration(decoration);
        recyclerView.setAdapter(new CommonAdapter<GoodsItemsBean>(activity, R.layout.item_mall_valuse_image, dataBean.list) {

            @Override
            protected void convert(ViewHolder holder, GoodsItemsBean listBean, int position) {
                ImageLoaderUtils.displayImage(activity, listBean.imgUrl, holder.getView(R.id.image),R.mipmap.mall_valuse_png1);
                holder.setOnClickListener(R.id.image, v -> IndexPresenter.setOnClick(activity, listBean));
            }
        });

    }
}
